home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / easyrexx.lha / EasyREXX / Source / test2.c < prev   
Encoding:
C/C++ Source or Header  |  1994-11-30  |  2.8 KB  |  130 lines

  1. /*
  2.  *    File:                    test2.c
  3.  *    Description:    Small program to show how easy EasyRexx.library makes
  4.  *                                the AREXX handling.  Shows how to handle AREXX messages
  5.  *                                calling the userdata functions in the commandTable.  Must be
  6.  *                                linked with easyrexx.lib.
  7.  *
  8.  *    (C) 1994, Ketil Hunn
  9.  *
  10.  *    Set tab to 2 for best readability
  11.  *
  12.  */
  13.  
  14. #include <stdio.h>
  15.  
  16. #include <libraries/easyrexx.h>
  17. struct Library *EasyRexxBase;
  18.  
  19. BYTE done=FALSE;
  20.  
  21. #define    AREXX_CLEAR            1
  22. #define    AREXX_OPEN            2
  23. #define    AREXX_SAVEAS        3
  24. #define    AREXX_HELP            4
  25. #define    AREXX_TEXT            5
  26. #define    AREXX_ROW                6
  27. #define    AREXX_QUIT            7
  28.  
  29. LONG arexx_clear(struct ARexxContext *c)
  30. {
  31.     printf("CLEAR");
  32.     return RC_OK;
  33. }
  34.  
  35. LONG arexx_open(struct ARexxContext *c)
  36. {
  37.     printf("OPEN");
  38.     if(ARG(c, 1))
  39.         printf(" TEXT");
  40.     else
  41.         printf(" PROJECT");
  42.     if(ARG(c, 2))
  43.         printf(" '%s'", ARGSTRING(c,2));
  44.     return RC_OK;
  45. }
  46.  
  47. LONG arexx_saveas(struct ARexxContext *c)
  48. {
  49.     printf("SAVEAS '%s'", ARGSTRING(c,0));
  50.     return RC_OK;
  51. }
  52.  
  53. LONG arexx_help(struct ARexxContext *c)
  54. {
  55.     printf("HELP");
  56.     if(ARG(c, 0))
  57.         printf(" AMIGAGUIDE");
  58.     if(ARG(c, 1))
  59.         printf(" '%s'", ARGSTRING(c,1));
  60.     return RC_OK;
  61. }
  62.  
  63. LONG arexx_text(struct ARexxContext *c)
  64. {
  65.     printf("TEXT '%s'", ARGSTRING(c,0));
  66.     return RC_OK;
  67. }
  68.  
  69. LONG arexx_row(struct ARexxContext *c)
  70. {
  71.     printf("ROW %ld", ARGNUMBER(c,0));
  72.     return RC_OK;
  73. }
  74.  
  75. LONG arexx_quit(struct ARexxContext *c)
  76. {
  77.     printf("QUIT");
  78.     done=TRUE;
  79.     return RC_OK;
  80. }
  81.  
  82. /* This application supports these AREXX commands */
  83. struct ARexxCommandTable commandTable[]=
  84. {
  85. /*    ID          CMD       ARGUMENT TEMPLATE             USERDATA  */
  86.  
  87.     AREXX_CLEAR,    "CLEAR",        "FORCE/S",                                        arexx_clear,
  88.     AREXX_OPEN,        "OPEN",            "PROJECT/S,TEXT/S,NAME/F",        arexx_open,
  89.     AREXX_SAVEAS,    "SAVEAS",        "NAME/K",                                            arexx_saveas,
  90.     AREXX_HELP,        "HELP",            "AMIGAGUIDE/S,TOPIC/F",                arexx_help,
  91.     AREXX_TEXT,        "TEXT",            "TEXT/A/F",                                        arexx_text,
  92.     AREXX_ROW,        "ROW",            "ROWNUMBER/A/N",                            arexx_row,
  93.     AREXX_QUIT,        "QUIT",            NULL,                                                    arexx_quit,
  94.     TABLE_END,
  95. };
  96.  
  97. void main(int argc, char **argv)
  98. {
  99.     if(EasyRexxBase=OpenLibrary(EASYREXXNAME, EASYREXXVERSION))
  100.     {
  101.         struct ARexxContext    *context;
  102.  
  103.         if(context=AllocARexxContext(    ER_Portname,            "EASYREXX_TEST",
  104.                                                                     ER_CommandTable,    commandTable,
  105.                                                                     TAG_DONE))
  106.         {
  107.             ULONG signal;
  108.  
  109.             printf(    "Welcome to a small EasyRexx demonstration\n"
  110.                             "-----------------------------------------\n"
  111.                             "Open another shell and start the small\n"
  112.                             "AREXX script: rx test\n"
  113.                             "or doubleclick on the test.rexx icon.\n");
  114.             while(!done)
  115.             {
  116.                 signal=Wait(ER_SIGNAL(context));
  117.  
  118.                 if(signal & ER_SIGNAL(context))
  119.                 {
  120.                     printf("Received: ");
  121.                     HandleARexxFuncs(context);
  122.                     printf("\n");
  123.                 }
  124.             }
  125.             FreeARexxContext(context);
  126.         }
  127.         CloseLibrary(EasyRexxBase);
  128.     }
  129. }
  130.